<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h2>断网提醒事件</h2>
  <button id="notifyBtn">通知消息</button>
  <script>
    window.addEventListener('online', function() {
      alert('我又回来了！')
    })
    window.addEventListener('offline', function() {
      alert('我断网了！')
    })

    let notifyBtn = document.getElementById('notifyBtn')
    let options = {
      title: '来提醒了！',
      body: '快去学习去吧！'
    }

    notifyBtn.onclick = () => {
      new window.Notification(options.title, options)
    }
  </script>
</body>
</html>